<!DOCTYPE html>
<html>
<#include "../head.html">
    <body>
    <div class="mc">
        <div class="mc-l">
            <!--左侧导航---{-->
            <div id="navPanelContainer">
                <div class="system-logo cd"></div>
                <!--管理员信息---{-->
                <#include "../adminInfo.html">
                    <!--管理员信息---}-->
                    <div class="nav-wrap">
                        <#include "left.html">
                    </div>
            </div>
            <!--左侧导航---}-->
        </div>
        <div class="mc-m">
            <div class="navToggle"></div>
        </div>
        <div class="mc-r">
            <!--顶部导航---{-->
            <#include "../topNav.html">
                <!--顶部导航---}-->

                <!--面包屑导航---{-->
                <#assign moduleName="新增客户">
                    <#include "banner.html">
                        <!--面包屑导航---}-->

                        <!--工具栏--{-->
                        <div id="toolbar" class="clearfix">
                            <div class="toolbor-module search">
                                <input type="button" class="input-button return" value="返回" onclick="location.href='/admin/crm/queryCustomer.html'">
                            </div>
                        </div>
                        <!--工具栏--}-->

                        <div id="main" class="clearfix">
                            <form id="cust" name="form1" method="post" action="/admin/crm/addCustomer.html">
                                <div class="valBox w750 h300">
                                    <div class="top">
                                        <strong>新增客户</strong>
                                    </div>
                                    <div class="val clearfix">
                                        <ul>

                                            <li>
                                                <div class="title">身份证号码：</div>
                                                <div class="v">
                                                    <input id="identityNumber" type="text"  name="identityNumber" style="width:250px;"></input>
                                                </div>
                                            </li>

                                            <li>
                                                <div class="title">手机：</div>
                                                <div class="v">
                                                    <input id="phone" type="text" name="phone" style="width:250px;"/>
                                                </div>
                                            </li>
                                            <li>
                                                <div class="title">姓名：</div>
                                                <div class="v">
                                                    <input id="custName" type="text" name="custName" style="width:250px;"/>
                                                </div>
                                            </li>


                                            <li>
                                                <div class="title">性别：</div>
                                                <div class="v">
                                                    <input type="radio" name="gender" value="0"  checked="checked"  />保密
                                                    <input type="radio" name="gender" value="1"/>男
                                                    <input type="radio" name="gender" value="2"   />女

                                                </div>
                                            </li>

                                            <!--  esales start -->
                                            <li>
                                                <div class="title">理财方式：</div>
                                                <div class="v">
                                                    <input type="radio" name="financialType" value="1"  checked="checked"  />线上
                                                    <input type="radio" name="financialType" value="2"/>线下

                                                </div>
                                            </li>
                                            <li>
                                                <div class="title">风险承受能力：</div>
                                                <div class="v">
                                                    <input type="radio" name="riskCapacity" value="1"  checked="checked"  />低
                                                    <input type="radio" name="riskCapacity" value="2"/>中
                                                    <input type="radio" name="riskCapacity" value="3"/>高

                                                </div>
                                            </li>
                                            <li>
                                                <div class="title">注册意愿：</div>
                                                <div class="v">
                                                    <input type="radio" name="intention" value="1" checked="checked"  />低
                                                    <input type="radio" name="intention" value="2"/>中
                                                    <input type="radio" name="intention" value="3"/>高

                                                </div>
                                            </li>
                                            <!--  esales end -->


                                            <li>
                                                <div class="title">出生日期：</div>
                                                <div class="v">
                                                    <input type="text" name="birthday" style="width:250px;" onclick="change_picktime('yyyy-MM-dd')" readonly/>
                                                </div>
                                            </li>

                                            <li>
                                                <div class="title">客户邮箱：</div>
                                                <div class="v">
                                                    <input type="text"  name="email" style="width:250px;"></input>
                                                </div>
                                            </li>

                                            <li>
                                                <div class="title">通讯地址：</div>
                                                <div class="v">
                                                    <textarea name="addr" style="width:450px;"></textarea>
                                                </div>
                                            </li>
                                            <li>
                                                <div class="title">备注</div>
                                                <div class="v">
                                                    <textarea name="memo" style="width:450px;height: 150px"></textarea>
                                                </div>
                                            </li>
                                        </ul>
                                        <div class="other">
                                            <input type="hidden"  name="actionType" value="add" />
                                            <input type="hidden"  name="userName"  />
                                            <input type="submit"  name="reset" value="新增" class="input-button confirm"/>
                                        </div>
                                    </div>
                                </div>

                            </form>

                        </div>
        </div>
    </div>
    <div class="mc-b">
        <#include "../foot.html">
    </div>
    <#include "../jsPage.html">
        <script>
            $(function() {
//--------------------------------------------------【钱内助用户表是否存在验证】
                //表单验证
                var bIdentityNumber=false,
                    bPhone=false,
                    bCustName=false;
                $("#identityNumber").change(function() {
                    var identityNumber = $(this).val(),
                        sLength=identityNumber.length,
                        reg=/^[0-9][x]*/;
                    $(this).css("border","").next("span").remove();
                    if(identityNumber == ""){
                        bIdentityNumber=true;
                        return false;
                    }
                    if(!( sLength==15||sLength==18&&identityNumber.match(reg))){
                        $(this).css({
                            "border":"1px solid red"
                        }).after('<span style="color:red">&nbsp;&nbsp;身份证格式不正确！</span>');
                        bIdentityNumber=false;
                        return false;
                    }else{
                        bIdentityNumber=true;
                    }

                    $.post("/admin/crm/doAjaxCheck.html",{
                        identityNumber: identityNumber
                    }, function(data) {
                        var errorHtml='';
                        if(data.resultCode == 1){//客户已经存在
                            //data.resultData.user.custName && (bCustName=true;$("#custName").css("border","").next("span").remove());
                            //data.resultData.user.phone && (bPhone=true;$("#phone").css("border","").next("span").remove());
                            if(data.resultData.user.custName){
                                bCustName=true;
                                $("#custName").css("border","").next("span").remove()
                            }
                            if(data.resultData.user.phone){
                                bPhone=true
                                $("#phone").css("border","").next("span").remove()
                            }
                            $("input[name='custName']").val(data.resultData.user.custName);
                            $("input[name='phone']").val(data.resultData.user.phone);
                            $("input[name='gender'][value='"+data.resultData.user.gender+"']").attr("checked", "checked");
                            $("input[name='birthday']").val(data.resultData.user.birthday);
                            $("input[name='email']").val(data.resultData.user.email);
                            $("textarea[name='addr']").val(data.resultData.user.addr);
                            $("input[name='userName']").val(data.resultData.user.userName);

                        }
                    },"json");
                    bIdentityNumber=true;
                    return true;
                });

                //表单验证
                $("#phone").change(function() {
                    var phone = $(this).val();
                    $(this).css("border","").next("span").remove();
                    if(phone==""){
                        $(this).css({
                            "border":"1px solid red"
                        }).after('<span style="color:red">&nbsp;&nbsp;手机不能为空!</span>');
                        bPhone=false;
                        return false;
                    }
                    if(!phone.match(/^((13[0-9]{9})|(15[0-35-9][0-9]{8})|(17(0|[6-8])[0-9]{8})|(18[0-9]{9}))$/)){
                        $(this).css({
                            "border":"1px solid red"
                        }).after('<span style="color:red">&nbsp;&nbsp;手机格式不正确！</span>');
                        bPhone=false;
                        return false;
                    }
                    $.post("/admin/crm/doAjaxCheck.html",{
                        phone: phone
                    }, function(data) {
                        var errorHtml='';
                        if(data.resultCode == 1){//客户已经存在
                            $("input[name='identityNumber']").val(data.resultData.user.identityNumber);
                            $("input[name='custName']").val(data.resultData.user.custName);
                            $("input[name='phone']").val(data.resultData.user.phone);
                            $("input[name='gender'][value='"+data.resultData.user.gender+"']").attr("checked", "checked");
                            $("input[name='birthday']").val(data.resultData.user.birthday);
                            $("input[name='email']").val(data.resultData.user.email);
                            $("textarea[name='addr']").val(data.resultData.user.addr);
                            $("input[name='userName']").val(data.resultData.user.userName);

                        }
                    },"json");
                    bPhone=true;
                    return true;
                });

                //表单验证
                $("#custName").change(function() {
                    var custName = $(this).val();
                    $(this).css("border","").next("span").remove();
                    if(custName==""){
                        $(this).css({
                            "border":"1px solid red"
                        }).after('<span style="color:red">&nbsp;&nbsp;客户姓名不能为空!</span>');
                        bCustName=false;
                        return false;
                    }else{
                        bCustName=true;
                    }
                });


                $("#cust").submit(function(){
                    //alert(bIdentityNumber+","+bPhone+","+bCustName)
                    $("#identityNumber,#phone,#custName").change();
                    if($("#identityNumber").val()==""){
                        bIdentityNumber=true;
                    }
                    if(!(bIdentityNumber&&bPhone&&bCustName)){
                        return false;
                    }

                });


            });
        </script>
    </body>
</html>
